
// 从 sequelize 模块中导入 Model 、DataTypes
const { Model, DataTypes } = require('sequelize');
// 导入 sequelize 配置模块
const sequelize = require( '../utils/sequelize' );

// 定义
class Customer extends Model {
}

const attributes = {
    id: {
        type: DataTypes.STRING,
        primaryKey: true
    },
    username: DataTypes.STRING,
    password: DataTypes.STRING,
    salt: DataTypes.STRING,
    nickname: DataTypes.STRING,
    signUpTime: {
        type: DataTypes.DATE,
        // 明确数据库中使用的列名
        field: 'sign_up_time'
    },
    signUpIp: {
        type: DataTypes.STRING,
        field: 'sign_up_ip'
    }
}

const options = {
    sequelize: sequelize,
    timestamps: false,
    // 使用 tableName 指定该模型对应的数据库表名
    tableName: 't_customers',
    modelName: 'customer'
}

// 初始化
Customer.init( attributes , options );

module.exports = Customer ;